JavaBasic Extension

Create an Extension | Load an Extension | JavaBasic Help

Define a Function | Define a Variable | Define a Verb | Exception and Error

Extensibility is one of the most important design goals of JavaBasic. This is achieved by adding JavaBasic Extensions. A JavaBasic extension can enhance any one, or all of following JavaBasic components: variable type, expression, function and verb. New variable types, functions or verbs can be added to JavaBasic. Expression is expended by overriding the arithmetic operation method of the variable classes.

Only Restriction: You Have To Program JavaBasic Extension in Java.


Create an Extension

By deriving a class from jbExtension, you define a new extension to JavaBasic. You must override the method Install() in the class, and register your own variable types, functions and verbs inside it. See define a function, define a variable and define a verb.


Load an Extension

At runtime, you load in a new extension by command load. Load expect an URL string pointing to your extension class. For example:

              Load Java

will load an extension defined by the variable Java.


Define a Function

You define a function by deriving a class from jbFunction. Register the function by calling jbFunction.Register() (this is usually done is the extension's install method. ) A function must be registered before starting any command can use it. A function must provide three methods:
CloneCreate a copy of the function. This method is used by registry when a function is called
GrammarParse through the token list to check the grammar of the function. The starting position is the first token after the '('. The function must returning the position immediately after the ')'
EvaluateEvaluate (execute) a function. It returns the position same as method Grammar. This arrangement will let parser to continue the parsing of the rest of command. Returning value is saved in a protected member "value" in class jbVerb. This value is returned to expression builder by GetValue() method. In other word, you either save the result into the place holder "value", or override the method GetValue().


Define a Variable

You define a new variable type by deriving a class from jbVariable. Register the type by calling jbVariable.Register() (this is usually done is the extension's install method. ) The new type may override any / all arithmetic operations and type conversion routines (see source code.) All operations are left operand based.


Define a Verb

You define a new verb by deriving a class from jbVerb, Register the type by calling jbVerb.Register (this is usually done is the extension's install method. ) The new verb must override following methods:
CloneCreate a copy of this verb. This is called by registry
GrammarParse through the token list. The starting position is the first token immediately after the verb. It must completely consume the rest of the token, otherwise, through exception err_extra
ExecuteExecute the command, and return the next command to be executed by parser.
BuildBlockOverride this function if the verb ends a block command. For example, the next statement if the for...next block. BuilcBlock is called immediately after the grammar checking. Block is used to prevent flow-control verbs from entering the block. For example, the goto statement
BlockNextReturn first command after the block.
BlockForeReturn first command prior to the block
BuildReferenceIf a verb refers to other command, or starts a block of commands, override this method to make sure proper reference is assigned. For example, the goto statement, the for statement.


Override the System Type, Function and Verb

It is OK to override the system types, functions or verbs.


Exception and Error

Is current version of JavaBasic, all exceptions are an instance of jbException. Extension should use jbException, or its derived class for exception handling to secure that the command parser and interpreter can catch exceptions. The interpreter stops upon catch an exception.